package q1460_canBeEqual;

public class Solution {
    private volatile static Solution solution;

    /*
    用hash表直接看是不是每个数字的数量是不是一样即可
    或者两个数组都排序后用Arrays.equals()比较两个数组是不是一模一样
     */
    public boolean canBeEqual(int[] target, int[] arr) {
        int[] hash = new int[1005];
        for (int i = 0; i < arr.length; ++i) {
            hash[arr[i]]++;
            hash[target[i]]--;
        }
        for (int i : hash) {
            if (i != 0) return false;
        }
        return true;
    }

    private Solution() {}
    public static Solution getInstance() {
        if (solution == null) {
            synchronized (Solution.class) {
                if (solution == null) {
                    solution = new Solution();
                }
            }
        }
        return solution;
    }

}


